<template>
  <div class="box">
    <div class="good-item" v-for="item in goods" @click="itemClick(item)">
      <img :src="showImage(item)" @load="imgLoad">
      <div class="good-info">
        <p class="title">{{item.title}}</p>
        <span class="price">{{item.price}}</span>
        <span class="collect">{{item.cfav}}</span>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "GoodsList",
    props:{
      goods:{
        type:Array,
        default(){return []}
      }
    },
    methods:{
      imgLoad(){
        this.$bus.$emit('imgLoad')
      },
      itemClick(item){
        this.$router.push({
          path:'/detail',
          query:{iid:item.iid}
        })
      }
    },
    computed:{
      showImage(){
        return (item)=>{return item.img || item.image || item.show.img}
      }
    }
  }
</script>

<style scoped>
  .box{
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    padding: 5px;
  }
  .good-item{
    width: 48%;
    font-size: 12px;
    text-align: center;
    position: relative;
    padding-bottom: 40px;
  }
  img{
    width: 100%;
    border-radius: 5px;
  }
  .good-info{
    position: absolute;
    bottom: 5px;
    width: 100%;
  }
  .title{
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .price{
    color: var(--color-high-text);
    margin-right: 20px;
  }
  .collect{
    text-align: center;
  }
  .collect::before {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    background-image: url("~assets/img/common/collect.svg");
    background-size: 14px;
    margin-left: -15px;
  }
</style>